<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *果树分类管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['shoutype']=$this->shoutype;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_farmer_gclassify',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'果树分类列表'),
			array('op'=>'edit','title'=>'添加果树分类'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'果树分类名称','type'=>'string'),
			array('name'=>'image','title'=>'果树分类图片','type'=>'image'),
			array('type'=>'radio','title'=>'收益模式','name'=>'shoutype','options'=>'shoutype','help'=>'【线下分批收益】：属于多次采摘，多次发货。线上将不处理收益流程；'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_farmer_gclassify',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回果树分类列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'分类名称','name'=>'title','help'=>''),
					array('type'=>'image','title'=>'分类图片','name'=>'image','help'=>''),
					array('type'=>'radio','title'=>'收益模式','name'=>'shoutype','options'=>'shoutype','help'=>'【线下分批收益】：属于多次采摘，多次发货。线上将不处理收益流程；'),
					array('type'=>'string','title'=>'排序','name'=>'paixu','help'=>'填写数字，按从小到大排序展示'),
					array('type'=>'text','title'=>'简介','name'=>'remark','help'=>''),
					array('type'=>'string','title'=>'认领协议标题','name'=>'xieyi_title'),
					array('type'=>'richtext','title'=>'认领协议内容','name'=>'xieyi_content'),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'image'=>trim($postdata['image']),
		'remark'=>trim($postdata['remark']),
		'paixu'=>intval($postdata['paixu']),
		'shoutype'=>intval($postdata['shoutype']),
		'xieyi_title'=>trim($postdata['xieyi_title']),
		'xieyi_content'=>trim($postdata['xieyi_content']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_farmer_gclassify',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_farmer_gclassify',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_farmer_gclassify',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}